<template>
  <div>
    <a-modal
      v-model:open="open"
      centered
      width="416px"
      title="确定删除"
      :confirm-loading="confirmLoading"
      :mask-closable="false"
      :body-style="{ 'padding-bottom': '0' }"
      destroy-on-close
      @ok="handleOk"
      @cancel="onCancel"
    >
      <div>
        <a-radio-group v-model:value="orgId">
          <a-radio value="1">当前班级</a-radio>
          <a-radio value="2">所有适学班级</a-radio>
        </a-radio-group>
        <p>此教学案例将被删除，对应班级不可见，请确认操作</p>
      </div>
    </a-modal>
  </div>
</template>

<script setup lang="ts">
  import { message } from 'ant-design-vue'
  import { reactive, ref } from 'vue'

  import { learningTasksManageApi } from '@/services/api/aigc-admin'
  const props = defineProps({
    id: {
      type: String,
      default: ''
    },
    visibleModal: {
      type: Boolean,
      default: false
    },
    orgId: {
      type: String,
      default: ''
    }
  })

  const orgId = ref<string>('1')

  // const emits = defineEmits(['update:visibleModal', 'ok', 'onCancel'])
  const emits = defineEmits<{
    (e: 'update:visibleModal', bool: boolean): void
    (e: 'success'): void
    (e: 'onCancel'): void
  }>()
  const open = ref(false)

  const onCancel = () => {
    // emits('update:visibleModal', false)
    open.value = false
  }
  const confirmLoading = ref<boolean>(false)
  const handleOk = async (): Promise<void> => {
    try {
      confirmLoading.value = true
      const classId = orgId.value === '1' ? props.orgId : null
      const res = await learningTasksManageApi.del({ classId, id: props.id }, { isAddUid: true })

      message.success('删除成功')
      console.log(res)
      emits('success')
      open.value = false
    } catch (error) {
      console.error(error)
    }
    confirmLoading.value = false
  }

  defineExpose({
    open: () => {
      open.value = true
      // initList()
    }
  })
</script>

<style lang="less" scoped>
  p {
    margin-top: 8px;
    line-height: 22px;
    color: rgba(21, 23, 27, 0.95);
  }
</style>
